package com.itheima.config;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import java.nio.charset.StandardCharsets;
import java.util.List;

@Configuration
@ComponentScan("com.itheima.controller")
//开启json数据类型自动转换
@EnableWebMvc//开启springmvc扩展功能支持：json字符串与java对象转换、日期格式转化支持、定义格式转换工厂等等
public class SpringMvcConfig extends WebMvcConfigurationSupport {
    @Override
    protected void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        StringHttpMessageConverter con = new StringHttpMessageConverter();
        con.setDefaultCharset(StandardCharsets.UTF_8);
        con.setWriteAcceptCharset(true);
        converters.add(con);
        super.configureMessageConverters(converters);
    }


}
